CM3D2 Converter.misc_TEXT_HT_header

  1# 「テキストエディター」エリア → ヘッダー
  2import bpy
  3from . import common
  4from . import compat
  5from .translations.pgettext_functions import *
  6
  7
  8# メニュー等に項目追加
  9def menu_func(self, context):
 10    texts = bpy.data.texts
 11    text_keys = texts.keys()
 12    self.layout.label(text="CM3D2用:", icon_value=common.kiss_icon())
 13    row = self.layout.row(align=True)
 14    if 'BoneData' in text_keys:
 15        txt = bpy.data.texts['BoneData']
 16        line_count = 0
 17        for line in txt.as_string().split('\n'):
 18            if line:
 19                line_count += 1
 20        row.operator('text.show_text', icon='ARMATURE_DATA', text=f_iface_("BoneData ({})", line_count, msgctxt='Operator')).name = 'BoneData'
 21    if 'LocalBoneData' in text_keys:
 22        txt = bpy.data.texts['LocalBoneData']
 23        line_count = 0
 24        for line in txt.as_string().split('\n'):
 25            if line:
 26                line_count += 1
 27        row.operator('text.show_text', icon='BONE_DATA', text=f_iface_("LocalBoneData ({})", line_count, msgctxt='Operator')).name = 'LocalBoneData'
 28    if 'BoneData' in text_keys and 'LocalBoneData' in text_keys:
 29        if 'BoneData' in texts:
 30            if 'BaseBone' not in texts['BoneData']:
 31                texts['BoneData']['BaseBone'] = ""
 32            row.prop(texts['BoneData'], '["BaseBone"]', text="")
 33        row.operator('text.copy_text_bone_data', icon='COPYDOWN', text="")
 34        row.operator('text.paste_text_bone_data', icon='PASTEDOWN', text="")
 35    if "Material:0" in text_keys:
 36        self.layout.label(text="", icon='MATERIAL_DATA')
 37        row = self.layout.row(align=True)
 38        pass_count = 0
 39        for i in range(99):
 40            name = "Material:" + str(i)
 41            if name in text_keys:
 42                sub_row = row.row(align=True)
 43                sub_row.scale_x = 0.75
 44                sub_row.operator('text.show_text', text=str(i)).name = name
 45            else:
 46                pass_count += 1
 47            if 9 < pass_count:
 48                break
 49        if "Material:0" in text_keys:
 50            row.operator('text.remove_all_material_texts', icon='X', text="")
 51
 52
 53@compat.BlRegister()
 54class CNV_OT_show_text(bpy.types.Operator):
 55    bl_idname = 'text.show_text'
 56    bl_label = "テキストを表示"
 57    bl_description = "指定したテキストをこの領域に表示します"
 58    bl_options = {'REGISTER', 'UNDO'}
 59
 60    name = bpy.props.StringProperty(name="テキスト名")
 61
 62    @classmethod
 63    def poll(cls, context):
 64        return hasattr(context.space_data, 'text')
 65
 66    def execute(self, context):
 67        context.space_data.text = bpy.data.texts[self.name]
 68        return {'FINISHED'}
 69
 70
 71@compat.BlRegister()
 72class CNV_OT_copy_text_bone_data(bpy.types.Operator):
 73    bl_idname = 'text.copy_text_bone_data'
 74    bl_label = "テキストのボーン情報をコピー"
 75    bl_description = "テキストのボーン情報をカスタムプロパティへ貼付ける形にしてクリップボードにコピーします"
 76    bl_options = {'REGISTER', 'UNDO'}
 77
 78    @classmethod
 79    def poll(cls, context):
 80        texts = context.blend_data.texts
 81        return 'BoneData' in texts and 'LocalBoneData' in texts
 82
 83    def execute(self, context):
 84        output_text = ""
 85        if 'BaseBone' in context.blend_data.texts['BoneData']:
 86            output_text += "BaseBone:" + context.blend_data.texts['BoneData']['BaseBone'] + "\n"
 87        for line in context.blend_data.texts['BoneData'].as_string().split('\n'):
 88            if not line:
 89                continue
 90            output_text += "BoneData:" + line + "\n"
 91        for line in context.blend_data.texts['LocalBoneData'].as_string().split('\n'):
 92            if not line:
 93                continue
 94            output_text += "LocalBoneData:" + line + "\n"
 95        context.window_manager.clipboard = output_text
 96        self.report(type={'INFO'}, message="ボーン情報をクリップボードにコピーしました")
 97        return {'FINISHED'}
 98
 99
100@compat.BlRegister()
101class CNV_OT_paste_text_bone_data(bpy.types.Operator):
102    bl_idname = 'text.paste_text_bone_data'
103    bl_label = "テキストのボーン情報を貼付け"
104    bl_description = "クリップボード内のボーン情報をテキストデータに貼付けます"
105    bl_options = {'REGISTER', 'UNDO'}
106
107    @classmethod
108    def poll(cls, context):
109        clipboard = context.window_manager.clipboard
110        return "BoneData:" in clipboard and "LocalBoneData:" in clipboard
111
112    def execute(self, context):
113        if "BoneData" in context.blend_data.texts:
114            bone_data_text = context.blend_data.texts["BoneData"]
115            bone_data_text.clear()
116        else:
117            bone_data_text = context.blend_data.texts.new("BoneData")
118        if "LocalBoneData" in context.blend_data.texts:
119            local_bone_data_text = context.blend_data.texts["LocalBoneData"]
120            local_bone_data_text.clear()
121        else:
122            local_bone_data_text = context.blend_data.texts.new("LocalBoneData")
123
124        clipboard = context.window_manager.clipboard
125        for line in clipboard.split("\n"):
126            if line.startswith('BaseBone:'):
127                info = line[9:]  # len('BaseData:') == 9
128                bone_data_text['BaseBone'] = info
129                local_bone_data_text['BaseBone'] = info
130                continue
131            if line.startswith('BoneData:'):
132                if line.count(',') >= 4:
133                    bone_data_text.write(line[9:] + "\n")  # len('BoneData:') == 9
134                continue
135            if line.startswith('LocalBoneData:'):
136                if line.count(',') == 1:
137                    local_bone_data_text.write(line[14:] + "\n")  # len('LocalBoneData:') == 14
138        bone_data_text.current_line_index = 0
139        local_bone_data_text.current_line_index = 0
140        self.report(type={'INFO'}, message="ボーン情報をクリップボードから貼付けました")
141        return {'FINISHED'}
142
143
144@compat.BlRegister()
145class CNV_OT_remove_all_material_texts(bpy.types.Operator):
146    bl_idname = 'text.remove_all_material_texts'
147    bl_label = "マテリアル情報テキストを全削除"
148    bl_description = "CM3D2で使用できるマテリアルテキストを全て削除します"
149    bl_options = {'REGISTER', 'UNDO'}
150
151    is_keep_used_material = bpy.props.BoolProperty(name="使用する分は保管", default=True)
152
153    @classmethod
154    def poll(cls, context):
155        return "Material:0" in context.blend_data.texts
156
157    def invoke(self, context, event):
158        return context.window_manager.invoke_props_dialog(self)
159
160    def draw(self, context):
161        self.layout.prop(self, 'is_keep_used_material')
162
163    def execute(self, context):
164        remove_texts = []
165        pass_count = 0
166        for i in range(9999):
167            name = "Material:" + str(i)
168            if name in context.blend_data.texts:
169                remove_texts.append(context.blend_data.texts[name])
170            else:
171                pass_count += 1
172            if 10 < pass_count:
173                break
174        if self.is_keep_used_material:
175            ob = context.active_object
176            if ob:
177                remove_texts = remove_texts[len(ob.material_slots):]
178        for txt in remove_texts:
179            context.blend_data.texts.remove(txt)
180        return {'FINISHED'}
@compat.BlRegister()
class CNV_OT_show_text(bpy_types.Operator):
54@compat.BlRegister()
55class CNV_OT_show_text(bpy.types.Operator):
56    bl_idname = 'text.show_text'
57    bl_label = "テキストを表示"
58    bl_description = "指定したテキストをこの領域に表示します"
59    bl_options = {'REGISTER', 'UNDO'}
60
61    name = bpy.props.StringProperty(name="テキスト名")
62
63    @classmethod
64    def poll(cls, context):
65        return hasattr(context.space_data, 'text')
66
67    def execute(self, context):
68        context.space_data.text = bpy.data.texts[self.name]
69        return {'FINISHED'}
bl_idname = 'text.show_text'
bl_label = 'テキストを表示'
bl_description = '指定したテキストをこの領域に表示します'
bl_options = {'REGISTER', 'UNDO'}
name: <_PropertyDeferred, <built-in function StringProperty>, {'name': 'テキスト名', 'attr': 'name'}> = <_PropertyDeferred, <built-in function StringProperty>, {'name': 'テキスト名', 'attr': 'name'}>
@classmethod
def poll(cls, context):
63    @classmethod
64    def poll(cls, context):
65        return hasattr(context.space_data, 'text')
def execute(self, context):
67    def execute(self, context):
68        context.space_data.text = bpy.data.texts[self.name]
69        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("TEXT_OT_show_text")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
items
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_copy_text_bone_data(bpy_types.Operator):
72@compat.BlRegister()
73class CNV_OT_copy_text_bone_data(bpy.types.Operator):
74    bl_idname = 'text.copy_text_bone_data'
75    bl_label = "テキストのボーン情報をコピー"
76    bl_description = "テキストのボーン情報をカスタムプロパティへ貼付ける形にしてクリップボードにコピーします"
77    bl_options = {'REGISTER', 'UNDO'}
78
79    @classmethod
80    def poll(cls, context):
81        texts = context.blend_data.texts
82        return 'BoneData' in texts and 'LocalBoneData' in texts
83
84    def execute(self, context):
85        output_text = ""
86        if 'BaseBone' in context.blend_data.texts['BoneData']:
87            output_text += "BaseBone:" + context.blend_data.texts['BoneData']['BaseBone'] + "\n"
88        for line in context.blend_data.texts['BoneData'].as_string().split('\n'):
89            if not line:
90                continue
91            output_text += "BoneData:" + line + "\n"
92        for line in context.blend_data.texts['LocalBoneData'].as_string().split('\n'):
93            if not line:
94                continue
95            output_text += "LocalBoneData:" + line + "\n"
96        context.window_manager.clipboard = output_text
97        self.report(type={'INFO'}, message="ボーン情報をクリップボードにコピーしました")
98        return {'FINISHED'}
bl_idname = 'text.copy_text_bone_data'
bl_label = 'テキストのボーン情報をコピー'
bl_description = 'テキストのボーン情報をカスタムプロパティへ貼付ける形にしてクリップボードにコピーします'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
79    @classmethod
80    def poll(cls, context):
81        texts = context.blend_data.texts
82        return 'BoneData' in texts and 'LocalBoneData' in texts
def execute(self, context):
84    def execute(self, context):
85        output_text = ""
86        if 'BaseBone' in context.blend_data.texts['BoneData']:
87            output_text += "BaseBone:" + context.blend_data.texts['BoneData']['BaseBone'] + "\n"
88        for line in context.blend_data.texts['BoneData'].as_string().split('\n'):
89            if not line:
90                continue
91            output_text += "BoneData:" + line + "\n"
92        for line in context.blend_data.texts['LocalBoneData'].as_string().split('\n'):
93            if not line:
94                continue
95            output_text += "LocalBoneData:" + line + "\n"
96        context.window_manager.clipboard = output_text
97        self.report(type={'INFO'}, message="ボーン情報をクリップボードにコピーしました")
98        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("TEXT_OT_copy_text_bone_data")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
items
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_paste_text_bone_data(bpy_types.Operator):
101@compat.BlRegister()
102class CNV_OT_paste_text_bone_data(bpy.types.Operator):
103    bl_idname = 'text.paste_text_bone_data'
104    bl_label = "テキストのボーン情報を貼付け"
105    bl_description = "クリップボード内のボーン情報をテキストデータに貼付けます"
106    bl_options = {'REGISTER', 'UNDO'}
107
108    @classmethod
109    def poll(cls, context):
110        clipboard = context.window_manager.clipboard
111        return "BoneData:" in clipboard and "LocalBoneData:" in clipboard
112
113    def execute(self, context):
114        if "BoneData" in context.blend_data.texts:
115            bone_data_text = context.blend_data.texts["BoneData"]
116            bone_data_text.clear()
117        else:
118            bone_data_text = context.blend_data.texts.new("BoneData")
119        if "LocalBoneData" in context.blend_data.texts:
120            local_bone_data_text = context.blend_data.texts["LocalBoneData"]
121            local_bone_data_text.clear()
122        else:
123            local_bone_data_text = context.blend_data.texts.new("LocalBoneData")
124
125        clipboard = context.window_manager.clipboard
126        for line in clipboard.split("\n"):
127            if line.startswith('BaseBone:'):
128                info = line[9:]  # len('BaseData:') == 9
129                bone_data_text['BaseBone'] = info
130                local_bone_data_text['BaseBone'] = info
131                continue
132            if line.startswith('BoneData:'):
133                if line.count(',') >= 4:
134                    bone_data_text.write(line[9:] + "\n")  # len('BoneData:') == 9
135                continue
136            if line.startswith('LocalBoneData:'):
137                if line.count(',') == 1:
138                    local_bone_data_text.write(line[14:] + "\n")  # len('LocalBoneData:') == 14
139        bone_data_text.current_line_index = 0
140        local_bone_data_text.current_line_index = 0
141        self.report(type={'INFO'}, message="ボーン情報をクリップボードから貼付けました")
142        return {'FINISHED'}
bl_idname = 'text.paste_text_bone_data'
bl_label = 'テキストのボーン情報を貼付け'
bl_description = 'クリップボード内のボーン情報をテキストデータに貼付けます'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
108    @classmethod
109    def poll(cls, context):
110        clipboard = context.window_manager.clipboard
111        return "BoneData:" in clipboard and "LocalBoneData:" in clipboard
def execute(self, context):
113    def execute(self, context):
114        if "BoneData" in context.blend_data.texts:
115            bone_data_text = context.blend_data.texts["BoneData"]
116            bone_data_text.clear()
117        else:
118            bone_data_text = context.blend_data.texts.new("BoneData")
119        if "LocalBoneData" in context.blend_data.texts:
120            local_bone_data_text = context.blend_data.texts["LocalBoneData"]
121            local_bone_data_text.clear()
122        else:
123            local_bone_data_text = context.blend_data.texts.new("LocalBoneData")
124
125        clipboard = context.window_manager.clipboard
126        for line in clipboard.split("\n"):
127            if line.startswith('BaseBone:'):
128                info = line[9:]  # len('BaseData:') == 9
129                bone_data_text['BaseBone'] = info
130                local_bone_data_text['BaseBone'] = info
131                continue
132            if line.startswith('BoneData:'):
133                if line.count(',') >= 4:
134                    bone_data_text.write(line[9:] + "\n")  # len('BoneData:') == 9
135                continue
136            if line.startswith('LocalBoneData:'):
137                if line.count(',') == 1:
138                    local_bone_data_text.write(line[14:] + "\n")  # len('LocalBoneData:') == 14
139        bone_data_text.current_line_index = 0
140        local_bone_data_text.current_line_index = 0
141        self.report(type={'INFO'}, message="ボーン情報をクリップボードから貼付けました")
142        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("TEXT_OT_paste_text_bone_data")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
items
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data
@compat.BlRegister()
class CNV_OT_remove_all_material_texts(bpy_types.Operator):
145@compat.BlRegister()
146class CNV_OT_remove_all_material_texts(bpy.types.Operator):
147    bl_idname = 'text.remove_all_material_texts'
148    bl_label = "マテリアル情報テキストを全削除"
149    bl_description = "CM3D2で使用できるマテリアルテキストを全て削除します"
150    bl_options = {'REGISTER', 'UNDO'}
151
152    is_keep_used_material = bpy.props.BoolProperty(name="使用する分は保管", default=True)
153
154    @classmethod
155    def poll(cls, context):
156        return "Material:0" in context.blend_data.texts
157
158    def invoke(self, context, event):
159        return context.window_manager.invoke_props_dialog(self)
160
161    def draw(self, context):
162        self.layout.prop(self, 'is_keep_used_material')
163
164    def execute(self, context):
165        remove_texts = []
166        pass_count = 0
167        for i in range(9999):
168            name = "Material:" + str(i)
169            if name in context.blend_data.texts:
170                remove_texts.append(context.blend_data.texts[name])
171            else:
172                pass_count += 1
173            if 10 < pass_count:
174                break
175        if self.is_keep_used_material:
176            ob = context.active_object
177            if ob:
178                remove_texts = remove_texts[len(ob.material_slots):]
179        for txt in remove_texts:
180            context.blend_data.texts.remove(txt)
181        return {'FINISHED'}
bl_idname = 'text.remove_all_material_texts'
bl_label = 'マテリアル情報テキストを全削除'
bl_description = 'CM3D2で使用できるマテリアルテキストを全て削除します'
bl_options = {'REGISTER', 'UNDO'}
is_keep_used_material: <_PropertyDeferred, <built-in function BoolProperty>, {'name': '使用する分は保管', 'default': True, 'attr': 'is_keep_used_material'}> = <_PropertyDeferred, <built-in function BoolProperty>, {'name': '使用する分は保管', 'default': True, 'attr': 'is_keep_used_material'}>
@classmethod
def poll(cls, context):
154    @classmethod
155    def poll(cls, context):
156        return "Material:0" in context.blend_data.texts
def invoke(self, context, event):
158    def invoke(self, context, event):
159        return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
161    def draw(self, context):
162        self.layout.prop(self, 'is_keep_used_material')
def execute(self, context):
164    def execute(self, context):
165        remove_texts = []
166        pass_count = 0
167        for i in range(9999):
168            name = "Material:" + str(i)
169            if name in context.blend_data.texts:
170                remove_texts.append(context.blend_data.texts[name])
171            else:
172                pass_count += 1
173            if 10 < pass_count:
174                break
175        if self.is_keep_used_material:
176            ob = context.active_object
177            if ob:
178                remove_texts = remove_texts[len(ob.material_slots):]
179        for txt in remove_texts:
180            context.blend_data.texts.remove(txt)
181        return {'FINISHED'}
bl_rna = <bpy_struct, Struct("TEXT_OT_remove_all_material_texts")>
Inherited Members
bpy_types.Operator
as_keywords
poll_message_set
builtins.bpy_struct
keys
values
items
get
pop
as_pointer
keyframe_insert
keyframe_delete
driver_add
driver_remove
is_property_set
property_unset
is_property_hidden
is_property_readonly
is_property_overridable_library
property_overridable_library_set
path_resolve
path_from_id
type_recast
bl_rna_get_subclass_py
bl_rna_get_subclass
id_properties_ensure
id_properties_clear
id_properties_ui
id_data